{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "61499bbf-f62b-4caf-9fba-026db5555191",
   "metadata": {
    "tags": []
   },
   "source": [
    "# break 和 continue 语句及循环中的 else 子句"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "966e21c3-5aa9-489a-8206-0827d178b7c6",
   "metadata": {},
   "source": [
    "**使用在嵌套中    所有的都是代码  每个判断内的判断就是嵌套**   \n",
    "\n",
    "基本都是在嵌套中使用"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ac4b8d85-cb36-42a3-bd81-e3346d8eedee",
   "metadata": {},
   "source": [
    "**break 执行流程图：**\n",
    "\n",
    "![img](https://www.runoob.com/wp-content/uploads/2014/09/E5A591EF-6515-4BCB-AEAA-A97ABEFC5D7D.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "92425df3-b5f9-4ee6-8de4-f9ba246a705a",
   "metadata": {},
   "source": [
    "**continue 执行流程图：**\n",
    "\n",
    "![img](https://www.runoob.com/wp-content/uploads/2014/09/8962A4F1-B78C-4877-B328-903366EA1470.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ea019f39-d84a-40e3-968d-149159c40e3c",
   "metadata": {},
   "source": [
    "![img](https://www.runoob.com/wp-content/uploads/2014/05/break-continue-536.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "12f30d38-e409-4c28-bf14-a4ab1eb78f4e",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n",
      "3\n",
      "循环结束。\n"
     ]
    }
   ],
   "source": [
    "n = 5\n",
    "while n > 0:\n",
    "    n -= 1\n",
    "    if n == 2:\n",
    "        break   # 有break 的时候直接出循环 后面的print 没有打印  \n",
    "    print(n)  \n",
    "print('循环结束。')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c6844346-2ba1-414d-9af3-8fef20431ea7",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n",
      "3\n",
      "1\n",
      "0\n",
      "循环结束。\n"
     ]
    }
   ],
   "source": [
    "n = 5\n",
    "while n > 0:\n",
    "    n -= 1\n",
    "    if n == 2:\n",
    "        continue   # 去上一个循环里面 从头开始   2 的时候跳过了后面的print 直接去到上面运行了\n",
    "    print(n)  \n",
    "print('循环结束。')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "63dadefd-9196-4f7d-9500-050d8f833be9",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "pass"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2ab9f5de-7cc6-44e0-8921-5dab00301e41",
   "metadata": {},
   "source": [
    "占用位置不执行\n",
    "\n",
    "写一个判断 执行的代码不确定写什么可以先用pass占用位置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "89a1c328-46e6-40c6-94cc-54a8d25176db",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "x,y = 1,2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "6d861965-72f2-4d0d-9f1e-1672da82d78f",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "incomplete input (4191253936.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Cell \u001b[1;32mIn[38], line 1\u001b[1;36m\u001b[0m\n\u001b[1;33m    if x > y:\u001b[0m\n\u001b[1;37m             ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m incomplete input\n"
     ]
    }
   ],
   "source": [
    "if x > y:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "73e2d741-4c0d-4421-b506-199a3ddf4f7a",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "if x > y:\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dc574d03-4d0d-447f-8559-b0628a2218a7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
